package com.sample.kokou;

import android.content.Intent;

import java.sql.SQLException;

import java.util.List;

import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.j256.ormlite.dao.Dao;

import android.view.View;

import android.widget.TextView;

import android.os.Bundle;

public class SqliteSampleActivity extends OrmLiteBaseActivity<SampleDBHelper> {
    private TextView view;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        view = GenericUtil.getView(this, R.id.displayTextView);
    }

    public void displayTable(View v) {
        try {
            Dao<Person, Integer> dao = getHelper().getDao(Person.class);
            List<Person> people = dao.queryForAll();
            view.setText("Table contents\n");
            view.append("--------------------------------------\n");
            for(Person person : people) {
                view.append(person.toString() + "\n");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public void newPerson(View v) {
    	Intent i = new Intent(this, NewPersonActivity.class);
        startActivity(i);
    }
}